<?php
namespace App\Http\Admin\Product\Controllers;

use Framework\BaseClass\Http\Admin\Controller;
use App\Http\Admin\Website\Models\Menu;
use App\Eloquent\Ygt\ProductFieldsModule;
use App\Engine\Product as EngineProduct;


class FieldsController extends Controller
{
    protected $modelName = 'ProductFieldsModule';
    protected $company = false;

    public function __construct()
    {
        parent::__construct();
        $this->model = new ProductFieldsModule();
        
    }

    protected function _vdata(){
        $fieldsType = EngineProduct::fieldsType();
        foreach ($fieldsType as $k=>$v){
            $fieldsType[$k] = $v['title'];
        }
        $data = ['fieldsType'=>json_encode($fieldsType)];

        return $data;
    }

    protected function _hdata($result){
        $result->transform(function($item){
            $comumnName = EngineProduct::getFieldColumn($item->field_type);
            $item->field_value = $item->$comumnName;
        });
        return $result;
    }

}